/*
 * 文件名：RoleInfoTransactionImp.java
 * 版权：Copyright by www.wootide.com
 * 描述：
 * 修改人：ozm
 * 修改时间：2013-1-30
 * 跟踪单号：
 * 修改单号：
 * 修改内容：
 */
package com.wootide.cms.service.reservation.orderby.transaction.imp;

import org.springframework.beans.BeanUtils;

import com.wootide.cms.common.CMSRuntimeException;
import com.wootide.cms.common.ErrorCodes;
import com.wootide.cms.common.Page;
import com.wootide.cms.common.QueryCondition;
import com.wootide.cms.common.QueryResults;
import com.wootide.cms.common.dao.CommonDao;
import com.wootide.cms.log.syslog.RunLog;
import com.wootide.cms.service.reservation.orderby.dao.OrderByInfoDao;
import com.wootide.cms.service.reservation.orderby.pojo.OrderByInfo;
import com.wootide.cms.service.reservation.orderby.transaction.OrderByInfoTransaction;

/**
 * 用户事物层实现层
 * 〈一句话功能简述〉
 * 〈功能详细描述〉
 * @author ozm
 * @version 2013-1-30
 * @see OrderByInfoTransactionImp
 * @since 2013-1-30上午9:44:19
 */
public class OrderByInfoTransactionImp implements OrderByInfoTransaction
{
    // 注入运行日志
    private RunLog runLog;
    
    //公共数据访问层实例
    private CommonDao commonDao;
    
  

    //角色数据访问层实例
    private OrderByInfoDao orderByInfoDao;
    
    /**
     * 
     * Description: 分页查询
     * Implement: <br>
     * @param page 分页参数
     * @param queryConditon 查询条件
     * @see
     * @return Result 结果对象
     * @author ozm2013-1-29下午1:23:32
     */
    public QueryResults queryForPages(Page page, QueryCondition queryConditon)
    {
        
        // 打印方法入口参数
        runLog.debug("page=" + page);
        runLog.debug("queryConditon=" + queryConditon);
        QueryResults queryResults = commonDao.queryForPages(page, queryConditon);
        return queryResults;
    }
    
    /**
     * 
     * Description: 添加一种预订方式
     * Implement: <br>
     * @param orderByInfo 要添加的预订方式
     * @see
     * @author ozm2013-1-29下午1:26:06
     */
    public void addOneOrderBy(OrderByInfo orderByInfo)
    {
        // 打印方法入口参数
        runLog.debug("orderByInfo=" + orderByInfo);
        // 根据用户名检查唯一性
        Integer num = orderByInfoDao.findNumByOrderByByName(orderByInfo.getOrderByName());
        //用户记录已经存在
        if (num > 0)
        {
            throw new CMSRuntimeException("OrderByInfo Existed!",
                    ErrorCodes.Reservation.OrderBy.ORDERBYEXIST);
        }
        
        commonDao.addOneObject(orderByInfo);
        
    }
    
    /**
     * 
     * Description: 修改一种预订方式
     * Implement: <br>
     * @param orderByInfo 要修该的预订方式
     * @see
     * @return OrderByInfo 修改的预订方式对象
     * @author ozm2013-1-29下午1:27:37
     */
    public OrderByInfo modOneOrderBy(OrderByInfo orderByInfo)
    {
        // 打印方法入口参数
        runLog.debug("orderByInfo=" + orderByInfo);
        OrderByInfo oldOrderByInfo = orderByInfoDao.findOneOrderByByOrderById(orderByInfo.getInnerIndex());
        
        //判断要修改的记录是否存在
        if (null == oldOrderByInfo)
        {
            throw new CMSRuntimeException("OrderByInfo not Exist!",
                    ErrorCodes.Reservation.OrderBy.ORDERBYNOTEXIST);
        }
        
        //获取原始数据副本
        OrderByInfo oldOrderByInfoCopy = new OrderByInfo();
        BeanUtils.copyProperties(oldOrderByInfo, oldOrderByInfoCopy);
        
        //修改用户信息
        oldOrderByInfo.setOrderByName(orderByInfo.getOrderByName());
        oldOrderByInfo.setOrderByDesc(orderByInfo.getOrderByDesc());
        oldOrderByInfo.setOrderByDiscount(orderByInfo.getOrderByDiscount());
        return oldOrderByInfoCopy;
    }
    
    /**
     * 
     * Description: 删除预订方式
     * Implement: <br>
     * @param innerIndexs 要删除的预订方式id
     * @return
     * @see
     * @return RoleInfo 要删除的预订方式信息
     * @author ozm2013-1-29下午4:17:56
     */
    public OrderByInfo delOneOrderBy(Integer innerIndex)
    {
        OrderByInfo oldOrderByInfo = orderByInfoDao.findOneOrderByByOrderById(innerIndex);
        //判断要删除的记录是否存在
        if (null == oldOrderByInfo)
        {
            throw new CMSRuntimeException("OrderByInfo not Exist!",
                    ErrorCodes.Reservation.OrderBy.ORDERBYNOTEXIST);
        }
        
        commonDao.delOneObject(oldOrderByInfo);
        //        BeanUtils.copyProperties(oldUserInfo, oldUserInfoCopy);
        return oldOrderByInfo;
    }
    
    /**
     * 
     * Description: 通过索引获取预订方式
     * Implement: <br>
     * @param innerIndex 指定的预订方式ID
     * @see
     * @return RoleInfo 要查询的预订方式
     * @author ozm2013-1-29下午3:55:17
     */
    public OrderByInfo viewOneOrderBy(Integer innerIndex)
    {
        // 打印方法入口参数
        runLog.debug("innerIndex=" + innerIndex);
        OrderByInfo orderByInfo = orderByInfoDao.findOneOrderByByOrderById(innerIndex);
        return orderByInfo;
    }

    public RunLog getRunLog()
    {
        return runLog;
    }

    public void setRunLog(RunLog runLog)
    {
        this.runLog = runLog;
    }

    public CommonDao getCommonDao()
    {
        return commonDao;
    }

    public void setCommonDao(CommonDao commonDao)
    {
        this.commonDao = commonDao;
    }

    public OrderByInfoDao getOrderByInfoDao()
    {
        return orderByInfoDao;
    }

    public void setOrderByInfoDao(OrderByInfoDao orderByInfoDao)
    {
        this.orderByInfoDao = orderByInfoDao;
    }

}
